package com.education.web.controller.course;

import com.education.common.annotation.Log;
import com.education.common.config.RuoYiConfig;
import com.education.common.core.controller.BaseController;
import com.education.common.core.domain.AjaxResult;
import com.education.common.core.page.TableDataInfo;
import com.education.common.enums.BusinessType;
import com.education.common.utils.file.FileUploadUtils;
import com.education.common.utils.file.FileUtils;
import com.education.common.utils.poi.ExcelUtil;
import com.education.course.domain.EduCourseSubjectVideo;
import com.education.course.service.IEduCourseSubjectVideoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * 课程视频Controller
 *
 * @author education
 * @date 2024-08-09
 */
@RestController
@RequestMapping("/common/upload")
public class UploadVideoController extends BaseController {

    /**
     * 视频上传
     *
     * @param file
     * @return
     * @throws Exception
     */
    @RequestMapping("/uploadVideo")
    public AjaxResult uploadVideo(@RequestParam(value = "file", required = true) MultipartFile file) throws Exception {
        String vdrul = "";
        AjaxResult ajax = AjaxResult.success();
        if (file != null) {
            try {
                ajax.put("fileName",  file.getOriginalFilename());
                vdrul = FileUploadUtils.upload(RuoYiConfig.getUploadPath()+"/video", file);
                ajax.put("url", vdrul);
            } catch (IOException e1) {
                return error(e1.toString());
            }
        }
        return ajax;
    }


    /**
     * 课件上传
     *
     * @param file
     * @return
     * @throws Exception
     */
    @RequestMapping("/uploadPdf")
    public AjaxResult uploadPdf(@RequestParam(value = "file", required = true) MultipartFile file) throws Exception {
        String vdrul = "";
        AjaxResult ajax = AjaxResult.success();
        if (file != null) {
            try {
                ajax.put("fileName",  file.getOriginalFilename());
                vdrul = FileUploadUtils.upload(RuoYiConfig.getUploadPath()+"/pdf", file);
                ajax.put("url", vdrul);
            } catch (IOException e1) {
                return error(e1.toString());
            }
        }
        return ajax;
    }
}
